<template>
<div class="main-container">
  <common_nav title="账号管理" backTitle="" :appPathObj="{}" :routerPath="{}"></common_nav>

  <div class="operator">
    <el-button type="primary" size="medium" @click="edit({})">添加账号</el-button>
  </div>
  <div class="table_data">
    <el-table :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        v-loading="loading"
        highlight-current-row
        ref="multipleTable"
        border
        class="eltable"
        :data="list" style="width: 100%">
      <el-table-column property="id" align="center" type='' label="编号" width="70"></el-table-column>
      <el-table-column property="nickname"  label="昵称"></el-table-column>
      <el-table-column property="mobile" label="手机号">
      </el-table-column>
      <el-table-column  property="status" label="状态">
        <template slot-scope="scope">
          <el-switch :active-value="active" :inactive-value="inactive" @change="update(scope.row,'status')" v-model="scope.row.status"></el-switch>
        </template>
      </el-table-column>
      <el-table-column property="remark" label="备注">
      </el-table-column>
      <el-table-column property="last_login_time" label="最后登录时间">
      </el-table-column>
      <el-table-column property="last_login_ip" label="最后登录ip">
      </el-table-column>
      <el-table-column property="create_time" label="创建时间">
      </el-table-column>
      <el-table-column label="操作" width="240">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row)" type="primary" >修改</el-button>
<!--
          <el-button size="mini" @click="setPermissions(scope.row)" type="primary" v-if="scope.row.level != 1">设置权限</el-button>
-->
        </template>
      </el-table-column>
    </el-table>
  </div>
  <div class="pagination">
    <Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="getList" />
  </div>
  <edit :show.sync="dialog.editStatus" :info="info" :list="list" @callFn="getList"></edit>
  <setPermissions :show.sync="dialog.setPermissionsStatus" :info="info" @callFn="getList"></setPermissions>

</div>
</template>

<script>
import { getList } from '@/api/user/user'
import Page from '@/components/common/Page.vue'
import edit from './edit';
import setPermissions from './setPermissions';

export default {
  name: "staff_index",
  components: {Page, edit, setPermissions},
  data() {
    return {
      loading: false,
      expand:true,
      inactive: 2,
      active: 1,
      list: [],
      info: {},
      device: 1,
      dialog: {
        editStatus: false,
        setPermissionsStatus: false
      },
      page_data: {
        page: 1,
        limit: 10,
        total: 0
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getList(this.page_data).then(res => {
        if (res.code == 200) {
          this.total = res.data.total
          this.list = res.data.data
          console.log(this.list)
        }
      })
    },
    edit(info) {
      this.info = info
      this.dialog.editStatus = true
    },
    update(row,field){
      updateExt({id:row.id, field: field,value:row[field]}).then(res=>{
        if (res.code == 0) {
          this.genTree()
        }
      })
    },
    setPermissions(info) {
      this.info = info
      this.dialog.setPermissionsStatus = true
    },
    handleCurrentChange(val) {
      this.id = val.id
      this.single = false
    },
  }
}
</script>

<style scoped>
.operator {
  margin: 10px 0 10px 0;
}
</style>